<?php
namespace App\Admin\Controllers;

use App\Models\NewsCat;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class NewsCatController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form($id)->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(NewsCat::class, function (Grid $grid) {
            $grid->id('ID')->sortable();
            $grid->journal_id ('期刊名称');
            $grid->name('栏目名称');
            $grid->language_type('语言类型');
            $grid->news_type ('新闻类型');
            $grid->position('菜单位置');
            $grid->created_at();
            $grid->updated_at();
        });
    }



    protected function form()
    {
        return Admin::form(NewsCat::class, function (Form $form){
            $form->display('id', 'ID');
            $journal_id = [
                0 => '--请选择期刊--',
                1 => '动物学研究',
            ];
            $form->select('journal_id', '期刊')->options($journal_id)->default(0)->rules('required');
            $form->text('name', '栏目名称')->rules('required');
            $language_type = [
                0 => '中文',
                1 => '英文',
            ];
            $form->select('language_type', '语言类型')->options($language_type)->default(0);
            $news_type = [
                0 => '普通新闻',
                1 => '图片新闻',
                2 => '商城新闻',
            ];
            $form->select('news_type', '新闻类型')->options($news_type)->default(0);
            $position = [
                0 => '顶部',
                1 => '其他',
            ];
            $form->select('position', '新闻类型')->options($position)->default(0);
            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}